package com.you.concurrent.thread.interrupt;

public class ThreadInterruptDemo2 {

    public static void main(String[] args) {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    if (Thread.currentThread().isInterrupted()) {
                        System.out.println("------self t1 thread print t1 state1----" + Thread.currentThread().isInterrupted());
                        //Thread.interrupted(); //复位标志
                        System.out.println("------self t1 thread print t1 state2----" + Thread.currentThread().isInterrupted());
                        break;
                    }
                }
                System.out.println("------self t1 thread print t1 state3----" + Thread.currentThread().isInterrupted());
                try {
                    Thread.sleep(100L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("------self t1 thread print t1 state4----" + Thread.currentThread().isInterrupted());
            }
        });
        System.out.println("------main print t1 state----" + t1.isInterrupted());
        t1.start();
        try {
            Thread.sleep(1L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //中断t1
        t1.interrupt();

    }
}
